import prompt from '@system.prompt';
import router from '@system.router';
export default {
    data:{

        num: 5,
        index:Math.floor(Math.random()*5),
        indexArray:[],
        goon:0,
        signal:0,
        count:0,
        againcountright:1,
        againcountwrong:1,
        text1: [ {
                     ques: "洪水严重时，可代替木（竹）筏自救逃生的用品有()",
                     cho:["门板，床板，木柜子等",
                     "铁门，玻璃板，铁板等",
                     "汽车，自行车，马车等"
                     ],
                     ans:0

                 },
                 {
                     ques: "洪水按照出现地区的不同，可分为()",
                     cho:["河流洪水，暴潮洪水，湖泊洪水",
                     "山洪，泥石流，溃坝洪水",
                     "融雪洪水，冰凌洪水，河流洪水",
                     ],
                     ans:0
                 },
                 {
                     ques: "为防洪而储备的必需物品应有()",
                     cho:["梯子，绳子，铁锹，斧子等",
                     "食物，饮水，炊具，衣物，火柴等",
                     "书籍，文具，清洗剂，消毒剂等",

                     ],
                     ans:1
                 },
                 {
                     ques: "为防止洪水涌入室内，有效的方法有（）",
                     cho:["将大门紧闭，必要时把一楼的窗户也关严",
                     "多准备脸盆，如有洪水进入可马上把水泼出去",
                     "在门槛外测堆上沙袋，并将大门下面的空隙用旧毛毯等堵住"
                     ],
                     ans:2
                 },
                 {
                     ques: "如有大洪水来临，为逃生可尽快转移到()",
                     cho:["能遮挡的地方，如高墙或建筑物的后面",
                     "人多的地方，如商场，影剧院，大街上",
                     "高处，如结实的楼顶，大树上",
                     ],
                     ans:2
                 },

        ],
        //题目乱序以及选项乱序
        rand:function(){
            this.againcountright=1;
            this.againcountwrong=1;
            while(this.goon==0){
                this.signal=0;
                var chu=Math.floor(Math.random()*5);
                for (var i=0; i<this.indexArray.length; i++)
                {
                    if(chu==this.indexArray[i]){
                        this.signal=1;
                        break;
                    }
                }
                if(this.signal==0){
                    this.index=chu;
                    this.indexArray.push(chu);
                    this.goon=1;
                }
            }
        },
//        回答正确响应
        select_respondY:function(){
            console.log("Yes");
            if(this.againcountright==1){
                this.$app.$def.globalData.rightNum=this.$app.$def.globalData.rightNum+1;
            }
            prompt.showToast({
                message: '回答正确',
                duration: 1000,
            });
            this.count=this.count+1;
            if(this.count==1){
                this.indexArray.push(this.index);
            }

            if(this.indexArray.length<5){
                this.goon=0;
                this.rand();
            }else{
                //                    router.back();
                prompt.showToast({
                    message: '恭喜！已完成本轮任务',
                    duration: 2000,
                    bottom:50
                });
                setTimeout(()=>{
                    router.push({
                        uri:'pages/questiontype/endtest/endtest',
                    })
                },2000);
            }
        },
//        回答错误响应
        select_respondN:function(){
            console.log("No");
            this.againcountright=0;
            if(this.againcountwrong==1){
                this.$app.$def.globalData.wrongNum=this.$app.$def.globalData.wrongNum+1;
            }
            this.againcountwrong=0;
            prompt.showDialog({
                title: '提示信息',
                message: '回答错误',
                buttons: [
                    {
                        text: '再想想',
                        color: '#666666',
                    },
                    {
                        text: '退出做题',
                        color: '#666666',
                    },
                ],
                success: function(data) {
                    //                     console.log('dialog success callback，click button : ' + data.index);
                    if(data.index==1){
                        router.push({
                            uri:'pages/questiontype/endtest/endtest'
                        })
                    }

                },
                cancel: function() {
                    console.log('dialog cancel callback');
                },
            });
        }


    },
//    结束测试
    select_over(){
        router.push({
            uri:'pages/questiontype/endtest/endtest'
        })


    },
    select1(){
        if(this.text1[this.index].ans==0){
            this.select_respondY();
        }else{
            this.select_respondN();
        }
    },
    select2(){
        if(this.text1[this.index].ans==1){
            this.select_respondY();
        }else{
            this.select_respondN();
        }
    },
    select3(){
        if(this.text1[this.index].ans==2){
            this.select_respondY();
        }else {
            this.select_respondN();
        }
    },
    select4(){
        if(this.text1[this.index].ans==3){
            this.select_respondY();
        }else {
            this.select_respondN();
        }
    },
}
